//viet ham sap xep cac phan tu trong mang theo thu tu tang dan va giam dan
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define MAX 100
void nhapmang(int a[],int n){
	printf("nhap mang: ");
	for(int i=0;i<n;i++){
		printf("\n\ta[%d]= ",i);
		scanf("%d",&a[i]);	
	}
}
void xuatmang(int a[], int n){
	printf("\nmang vua nhap vao la: ");
	for(int i=0; i<n; i++){
		printf("\t%d",a[i]);
	}
}
int sapxeptang(int a[],int n){
	int temp;
     for (int i=0; i<n-1;i++)
     	for(int j=i+1;j<n;j++)
     	    if(a[i]>a[j]){
     	          temp = a[i];
     	          a[i] = a[j];
     	          a[j] = temp;
		                 }
	printf("\nMang sap xep tang dan la: "); 
         for(int i=0;i<n;i++) 
         printf("\t%d",a[i]); 
     }
int sapxepgiam(int a[],int n){
	int temp;
     for (int i=0; i<n-1;i++)
     	for(int j=i+1;j<n;j++)
     	    if(a[i]<a[j]){
     	          temp = a[i];
     	          a[i] = a[j];
     	          a[j] = temp;
		                 }
	printf("\nMang sap xep giam dan la: "); 
         for(int i=0;i<n;i++) 
         printf("\t%d",a[i]); 
     }

int main(){
	int a[MAX];
	int n;
	printf("\nnhap vao so phan tu cua mang: ");
	scanf("%d",&n);
	nhapmang(a,n);
	xuatmang(a,n);
	sapxeptang(a,n);
	sapxepgiam(a,n);
	getch();
} 
